#include <stdio.h>

struct Student
{
    char num[10];
    char name[8];
    int score[3];
    float ave;
} stu[5];

int main()
{
    int i, j, sum;
    FILE *fp;

    for (i = 0; i < 5; i++)
    {
        printf("\ninput score of student %d:\n", i + 1);
        printf("NO.:");
        scanf("%s", stu[i].num);
        printf("name:");
        scanf("%s", stu[i].name);
        sum = 0;
        for (j = 0; j < 3; j++)
        {
            printf("score %d:", j + 1);
            scanf("%d", &stu[i].score[j]);
            sum += stu[i].score[j];
        }
        stu[i].ave = sum / 3.0;
    }

    fp = fopen("stud.txt", "wt"); // 打开文本文件进行写入操作
    for (i = 0; i < 5; i++)
    {
        fprintf(fp, "%s %s %d %d %d %.2f\n", stu[i].num, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].ave);
    }
    fclose(fp);

    fp = fopen("stud.txt", "rt"); // 打开文本文件进行读取操作
    for (i = 0; i < 5; i++)
    {
        fscanf(fp, "%s %s %d %d %d %f\n", stu[i].num, stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2], &stu[i].ave);
        printf("\n%s, %s, %d, %d, %d, %.2f\n", stu[i].num, stu[i].name, stu[i].score[0], stu[i].score[1], stu[i].score[2], stu[i].ave);
    }
    fclose(fp);

    return 0;
}